package com.leyou.controller;

import com.leyou.service.PageService;
import com.leyou.service.impl.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

//值不能写成restController
@Controller
@RequestMapping("item")
public class GoodsPageController {
    @Autowired
    private PageService pageService;

    @Autowired
    private FileService fileService;

    /**
     * 根据spuId查询spu,sku,spuDetail 规格参数组的信息等  需要跨服务查询.
     *
     * @param spuId
     * @param model
     * @return
     */
    @GetMapping("{spuId}.html")
    public String itemPage(@PathVariable("spuId") Long spuId, Model model) {
        Model model1 = model.addAllAttributes(pageService.queryData(spuId));
        // 判断是否需要生成新的页面
        if (!this.fileService.exists(spuId)) {
            //this.fileService.syncCreateHtml(spuId);
        }
        return "item";
    }
}
